package com.swt.service.impl;

import com.alibaba.druid.sql.visitor.functions.If;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.swt.domain.Admin;
import com.swt.service.TbManageUserService;
import com.swt.domain.TbManageUser;
import com.swt.mapper.TbManageUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author 苏
* @description 针对表【yesapi_xbinstore_tb_manage_user(B2C商城-后台用户表)】的数据库操作Service实现
* @createDate 2022-05-16 09:40:37
*/
@Service
public class TbManageUserServiceImpl implements TbManageUserService {
    @Autowired
    private TbManageUserMapper userMapper;
    @Override
    public List<TbManageUser> selectAllUser() {
        return userMapper.selectList(null);
    }

    @Override
    public int delectUser(String id) {
        return userMapper.deleteById(id);
    }

    @Override
    public int updateUser(TbManageUser user) {
        return userMapper.updateById(user);
    }

    @Override
    public int inserUser(TbManageUser user) {
        return userMapper.insert(user);
    }

    @Override
    public TbManageUser selectbyuserid(String id) {
        return userMapper.selectById(id);
    }

    @Override
    public Page<TbManageUser> pageuser(Integer page, Integer start ,TbManageUser user) {
        Page<TbManageUser> userPge = new Page<>(page,start);
        LambdaQueryWrapper<TbManageUser> us =new LambdaQueryWrapper<>();
        us.orderByDesc(TbManageUser::getCreateTime);
        if(user != null){
            us.like(StringUtils.isNotEmpty(user.getUsername()), TbManageUser::getUsername,user.getUsername());
            us.like(StringUtils.isNotEmpty(user.getPhone()), TbManageUser::getPhone,user.getPhone());
            us.like(StringUtils.isNotEmpty(user.getGender()), TbManageUser::getGender,user.getGender());
            us.like(StringUtils.isNotEmpty(user.getEmail()), TbManageUser::getEmail,user.getEmail());
            us.like(StringUtils.isNotEmpty(user.getName()), TbManageUser::getName,user.getName());

        }
        return userMapper.selectPage(userPge,us);
    }
}




